changes required to move from mysql
-
Hi,
I’ve recently migarted a website to wordpress and had to develop a plugin for a particular feature of the site.
The old mysql code was:
define ('DB_USER', 'abc'); define ('DB_PASSWORD', 'xyz'); define ('DB_HOST', 'localhost'); define ('DB_NAME', 'dodah'); $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die('Failure: ' . mysql_error() ); mysql_select_db(DB_NAME) or die ('Could not select database: ' . mysql_error() );followed by:
$query = "SELECT * FROM bookings WHERE bookingDate >= '$fromQuery' AND bookingDate <= '$toQuery'"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ $temp = $row['bookingDate']; .... }I’ve tried changing this to:
global $wpdb; $results = $wpdb->get_results("SELECT * FROM $wpdb->bookings WHERE bookingDate >= '$fromQuery' AND bookingDate <= '$toQuery'", ARRAY_A); $counter = 0; foreach ($results AS $result){ $temp = $result->bookingDate; ... }but to no avail.
If I put the old mysql code, including the db connection code, in the page it works fine but with the new code it gets rejected with an error in the sql query string.
The query code is printed out without the table name, so I get
SELECT * FROM WHERE bookingDate >= '$fromQuery' AND bookingDate <= '$toQuery'I followed the advice on https://make.ww.wp.xz.cn/core/2014/04/07/mysql-in-wordpress-3-9/
What am I missing?
Thanks
Paul
The topic ‘changes required to move from mysql’ is closed to new replies.