I am trying to move from MySQL
toMySQLi
but am having some problems. MySQLi
connection starts as shown below:
$langCon=mysqli_connect('localhost', 'root', '', 'english');
if (!$langCon) die('Couldn\'t connect: '.mysqli_error());
and I am trying to useMySQLi
to store my session data, however, I keep getting an error on my _write construct (It is unfinished, posting like this since the error occurs on line 56, the one with$stmt=...
):
function _write($id, $data){ /
global $langCon;
$stmt=mysqli_prepare($langCon,'REPLACE INTO `sess`(`id`,`access`,`data`) VALUES(?,?,?)');
$id = mysqli_real_escape_string($langCon,$id);
$data = mysqli_real_escape_string($langCon,$data);
$t=$_SERVER['REQUEST_TIME'];
return mysqli_query($langCon,"REPLACE INTO `sess`(`id`,`access`,`data`) VALUES('$id','$t','$data')");
}
The error given is: Warning: mysqli_prepare() expects parameter 1 to be mysqli, null given in [...]settings.php on line 56
(the line is $stmt=...)
Could anyone please tip me off on where my problem might be?
EDIT Var dump outside function,var_dump($langCon)
:
object(mysqli)#2 (18) { ["affected_rows"]=> int(0) ["client_info"]=> string(50) "mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $" ["client_version"]=> int(50008) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(10) "5.5.21-log" ["server_version"]=> int(50521) ["stat"]=> string(130) "Uptime: 373 Threads: 1 Questions: 5 Slow queries: 0 Opens: 34 Flush tables: 1 Open tables: 27 Queries per second avg: 0.013" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(5) ["warning_count"]=> int(0) }
Var dump inside function, global $langCon; var_dump($langCon);
: NULL.
$langCon
global there as well? – lanzz_write($id, $data)
. – AM-_write()
after you have connected? Because there is no way for us to know that from the code you posted. – lanzz