Page 1 of 1

Insert query

Posted: Sun Aug 03, 2008 9:57 pm
by Jeeee
I'm trying to use the MySqli class to add to my MySql DB but for some reason it doesn't work, but if I type the same line in the MySQL administrator panel everything works!!!

Code: Select all

 
 
$dbc = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE, DB_PORT);
if (!$dbc->query("INSERT INTO ftpcredentials (FTP_IP, FTP_USER, FTP_PWD, FTP_PORT, idFournisseur) VALUES ('122.122.122.122', 'test', 'test', '1234', '1')"))
{
      printf("Errorcode: %d\n", $dbc->error);
      printf("%d Row inserted.\n", $dbc->affected_rows);
}
 
I keep getting 0 rows inserted.

Thanks

Re: Insert query

Posted: Sun Aug 03, 2008 11:49 pm
by harshil
Hi,

I had not used MySqli. But below can be the reason the problem u r facing !!
When u will typing the same line in MySQL u r getting the things, because u will be
rewriting the insert query which is same in MySQL & MySqli.
But I think the problem will be the object that u r making for connection - [new mysqli]
Due to this connection is established to mysqli and not to mysql.


Re: Insert query

Posted: Mon Aug 04, 2008 2:13 pm
by Jeeee
Isn't Mysqli and extension of MySql??? Cause right now what I do in MySql_Query should work if I do the mysqli->query???

Unless I'm mistaken..

Re: Insert query

Posted: Mon Aug 04, 2008 2:55 pm
by ghurtado
Your query should work either way. Did you try running the SQL directly through the mysql command line or phpMyAdmin? what is the exact error message you get?

Re: Insert query

Posted: Mon Aug 04, 2008 3:27 pm
by Jeeee
No that's what I'm saying... If I execute that query in MySql Command line it works no problem, If I runit using the MySqli->query() thing I always get 0 rows inserted.

Re: Insert query

Posted: Mon Aug 04, 2008 3:35 pm
by Jeeee
Ok I got it to work... I guess I was trying to insert data in a int field!!!

Thank you to everyone and sorry for the stupidity!!!

Cheers

Re: Insert query

Posted: Mon Aug 04, 2008 3:38 pm
by RobertGonzalez
Make sure your error reporting is cranked up to E_ALL and display errors is on (which means you should be doing this locally and not on your production server).

Code: Select all

<?php
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE, DB_PORT);
 
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
 
$sql = "INSERT INTO ftpcredentials (FTP_IP, FTP_USER, FTP_PWD, FTP_PORT, idFournisseur) VALUES ('122.122.122.122', 'test', 'test', '1234', '1')";
 
if (!$db->query($sql)) {
    printf("Query failed: %s\n", $db->error);
} else {
    printf("Query ran. Rows affected: %s\n", $db->affected_rows);
}
 
$db->close();
?>
Run it and report your errors back.