This question already has an answer here:
Strangest thing going on. I'm able to run this just fine in XAMPP. But when I move to my server which uses a socket to connect, it connects, but I can't insert. And I'm wondering if its due to a socket and I need to do things differently. I changed to = new mysqli
as mysql_connect
doesn't work with a socket. But outside of that, I'm a bit lost. When I run test.php
I get
Error : ()
Test.PHP
<?php
$dbhost = "localhost";
$socket = ":/diskID/mysql/socket";
$dbname = "TUTORIALS";
$dbusername = "root";
$dbpassword = "password";
$mysqli = new mysqli($dbhost,$dbusername,$dbpassword,$dbname,$socket);
//Output any connection error
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$product_name = '"'.$mysqli->real_escape_string('P1234').'"';
//MySqli Insert Query
$insert_row = $mysqli->query("INSERT INTO tutorials_inf (name)VALUES($product_name)");
if ($insert_row) {
print 'Success! ID of last inserted record is : ' .$mysqli->insert_id .'<br />';
} else {
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
</div>