Mysqli ": mysqli_stmt_bind_param () parametre 1 mysqli_stmt olmasını beklediğini, boolean verilen Uyarı" atıyor

2 Cevap php

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I know that this code works on another site I've got but it's not playing ball today. I get three warnings:

Uyarı: mysqli_stmt_bind_param () parametre 1 mysqli_stmt olmasını beklediğini, hat 33 üzerinde / homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php verilen boolean

Uyarı: mysqli_execute () parametre 1 mysqli_stmt olmasını beklediğini, hat 34 üzerinde / homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php verilen boolean

Uyarı: mysqli_stmt_affected_rows () parametre 1 mysqli_stmt olmasını beklediğini, hat 35 üzerinde / homepages/14/d248783986/htdocs/subdomains/clients.bionic-comms.co.uk/httpdocs/carefree/process.php verilen boolean

Birisi bana bu anlamaya yardımcı olabilir?

Ben bu yardımcı olur PHP5'ta yükseltmek için htaccess kullanmak için yaşıyorum.

$connection = mysqli_connect($hostname, $username, $password, $dbname);

if (!$connection) {
    die('Connect Error: ' . mysqli_connect_error());
}

$query = "INSERT INTO entries (name, dob, school, postcode, date) VALUES (?,?,?,?,?)";
$stmt1 = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($stmt1, 'sssss',$name,$dob,$school,$postcode,$date);
mysqli_execute($stmt1);
if(mysqli_stmt_affected_rows($stmt1) != 1)
    die("issues");
mysqli_stmt_close($stmt1);
return "new";

DÜZENLEME

Biraz araştırma yaptıktan sonra o hazırlamak deyimi mysql4 top oynamıyor ortaya çıkmaktadır. Ben yeni bir MySQL5 veritabanı oluşturduk ama ben bağlanmaya çalıştığımda artık bu hatayı alıyorum:

Uyarı: mysqli_connect () [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'localhost :/ tmp/mysql5.sock' (1)

Herkes neden bu oluyor için herhangi bir fikir var mı?

2 Cevap

Sorun mysqli_prepare() gelir, hangi durumda getiri false, hata dolayısıyla 'verildi boolean'. Sorgu Tamam görünüyor gibi, hata $connection olmalıdır. Eğer bağlantı çalışır ve tanımlanmış olduğundan emin misin?

Bağlantı bu gibi bir şey olarak tanımlanmış olmalıdır:

$connection = mysqli_connect("localhost", "my_user", "my_password", "world");

Bağlantı düzgün tanımlanmış ise, bir şey yanlış giderse echo mysqli_connect_error() görmek için kullanabilirsiniz. Sen kodu başka sitede çalıştığını söyledi, böylece belki de kimlik bilgilerini veya ana değiştirmek için unuttum?

Add more error handling.
When the connection fails, mysqli_connect_error() can tell you more details.
When preparing the statement fails mysqli_error() has more infos about the error.
When executing the statement fails, ask mysqli_stmt_error(). And so on and on...
Any time a function/method of the mysqli module returns false to indicate an error, a) handle that error and b) decide whether it makes sense or not to continue. E.g. it doesn't make sense to continue with database operations when the connection failed. But it may make sense to continue inserting data when just one insertion failed (may make sense, may not).

Test etmek için böyle bir şey kullanabilirsiniz:

$connection = mysqli_connect(...);
if ( !$connection ) {
  die( 'connect error: '.mysqli_connect_error() );
}

$query = "INSERT INTO entries (name, dob, school, postcode, date) VALUES (?,?,?,?,?)";
$stmt1 = mysqli_prepare($connection, $query);
if ( !$stmt1 ) {
  die('mysqli error: '.mysqli_error($connection);
}
mysqli_stmt_bind_param($stmt1, 'sssss',$name,$dob,$school,$postcode,$date);
if ( !mysqli_execute($stmt1) ) {
  die( 'stmt error: '.mysqli_stmt_error($stmt1) );
}
...

Gerçek bir üretim ortamı için bu yaklaşım konuşkan olduğunu ve kolayca ölür ;-)