• Resolved link163

    (@link163)


    Hi!
    I’m very interested in your plugin, it seems amazing! The only problem (and it’s a quick question) is where am I suppose to put my PDO statement?

    I mean this line :
    $stmt = $dbh = new PDO(“mysql:host=$NomHost; dbname=$NomBD”, “$NomUser” , “”) ;

    Where is it supposed to go? I have an otherp lugin to put PHP code in a WP page, but it doesn’t seem to work…

    Thank you for helping me!

    https://ww.wp.xz.cn/plugins/wp-db-driver/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Marko Heijnen

    (@markoheijnen)

    This plugin replaces how WordPress handles database calls. You should always use the “wpdb” class WordPress provides and never make the connection yourself.

    Thread Starter link163

    (@link163)

    OK then, where do I tell WordPress to use this database with username and password?

    I just don’t understand where to write my SQL statements in my pages…

    Plugin Author Marko Heijnen

    (@markoheijnen)

    This plugin is a simple drop in for the WordPress database class. So it connects with the details in wp-config.php.

    If you need to make custom SQL statements then check out http://codex.ww.wp.xz.cn/Class_Reference/wpdb.

    Thread Starter link163

    (@link163)

    Interesting!
    Then what do I write on a WP page to access DB data? I wanna insert into a table, what do I write?

    Plugin Author Marko Heijnen

    (@markoheijnen)

    Unsure what kind of answer I need to give here. I see you are missing the basic of development or/and WordPress so below you see some additional resources. (If you need custom queries then you should read http://codex.ww.wp.xz.cn/Class_Reference/wpdb).

    But when you need to display post data then check out http://codex.ww.wp.xz.cn/Class_Reference/WP_Query.

    And when you need that data displayed on a certain post or page in WordPress then checkout http://codex.ww.wp.xz.cn/Shortcode_API.

    Thread Starter link163

    (@link163)

    All right, I’ll read that.

    In fact, what I want to do, is a command form on a WP page. In normal PHP, I would call my DB with PDO. But since I’m in WP, that’s why I’m so lost.

    How would you do an insert in table with that plugin enabled?

    Plugin Author Marko Heijnen

    (@markoheijnen)

    First of all this plugin doesn’t make it easier/harder to insert something in a table. It’s code you should not touch expect that it will run for you.

    First start with creating a shortcode or page template to display the form. See for the page templates: http://codex.ww.wp.xz.cn/Page_Templates.

    When you want to insert data into a custom database table then you do the following:

    $wpdb->insert(
    	'wp_mytable',
    	array(
    		'column1' => 'value1',
    		'column2' => 123
    	),
    	array(
    		'%s',
    		'%d'
    	)
    );
Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Where to write my PDO statement’ is closed to new replies.