0

Argh I can't get my head round this. I have a connection to a mySQL database:

function db_connect() {

  static $connection;

  if(!isset($connection)) {
    $config = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . "/cfi/config.ini");
    $connection = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']);    
  }


  if($connection === false) {
    return mysqli_connect_error();
  }

  return $connection;

}

I run it like so:

$connection = db_connect();

I then try and run an INSERT like so:

if (mysqli_query($connection, "INSERT INTO pending ('aw_id','in_stock') VALUES ('1','yes')")) {
  echo "success";
} else {
  echo "fail";
}

But it always fails... what am I missing?

I'm not sure if it helps but a var_dump of $connection is:

object(mysqli)#1 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $" ["client_version"]=> int(50011) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(6) "5.6.23" ["server_version"]=> int(50623) ["stat"]=> string(147) "Uptime: 684382 Threads: 3 Questions: 5532897 Slow queries: 14 Opens: 287168 Flush tables: 37 Open tables: 1024 Queries per second avg: 8.084" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(184926) ["warning_count"]=> int(0) } 

Grrrr!!

1
  • turn on error reporting and let me (us) know what it says. Commented Mar 11, 2015 at 10:07

1 Answer 1

3
INSERT INTO pending ('aw_id','in_stock') VALUES ('1','yes')

replace with

INSERT INTO pending (aw_id,in_stock) VALUES ('1','yes')
Sign up to request clarification or add additional context in comments.

2 Comments

I knew it would be something simple! Thanks!! Will accept your answer when timer runs down.
@Lee remember, when you are using columns names you cannot use apostrophe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.