Ben bu garip hata var ve nereden geldiğini anlamaya olamaz:
Warning: mysql_query(): 3 is not a valid MySQL-Link resource in (...)
Ne 3 ile var? Ben alamadım. Herkes bu hatayı kendilerini yaşadı?
PHP gibi dosyaları ve veritabanı bağlantıları gibi dış nesneler, bağlantıları tutmak için özel bir değişken olarak kaynaklarını kullanır. Her kaynak bir tamsayı id verilir. (Documentation)
Veritabanı bağlantısı olasılıkla Dan Breen belirtildiği gibi kaynak tutmak gerekiyordu değişken null beri, hata "Belirtilen değişken geçerli MySQL-Link kaynak değil" alırsınız başarısız olursa.
$link = mysql_connect('localsoth','baduser','badpass'); // failed connection
$result = mysql_query("SELECT 1", $link); // throws error
Eğer hata mesajı belirli bir kaynak kimliği alıyoruz yana, veritabanı bağlantısı muhtemel nedense beklenmedik biçimde kapatıldı. Sizin program hala bir kaynak kimliği ile bir değişken var, ama dış nesne artık yok. Bu may nedeniyle mysql_close() mysql_query için çağrı veya bağlantıyı kapattı, bir dış veritabanı hata önce bir yerde aramak olabilir.
$link = mysql_connect();
mysql_close($link);
// $link may still contain a resource identifier, but the external object is gone
mysql_query("SELECT 1", $link);
An issue with the mysql extension and mysql_connect() is that by default if you pass the same parameters in successive calls, it will re-use the existing connection rather than create a new one (Documentation). This can be fixed by passing true to the $new_link parameter.
I encountered this myself on a test system where the data from two separate databases in production were combined on to one test server, and in testing the mysql_xxx() function calls walked over each other and broke the system.
$link1 = mysql_connect('localhost','user','pass'); // resource id 1 is given
$link2 = mysql_connect('localhost','user','pass'); // resource id 1 is given again
mysql_close($link2); // the connection at resource id 1 is closed
mysql_query("SELECT 1", $link1); // will fail, since the connection was closed
Kullanma $new_link,
$link1 = mysql_connect('localhost','user','pass'); // resource id 1 is given
$link2 = mysql_connect('localhost','user','pass', true); // resource id 2 is given
mysql_close($link2); // the connection at resource id 2 is closed
mysql_query("SELECT 1", $link1); // the connection at resource id 1 is still open
Edit:
As an aside, I would recommend using the MySQLi extension or PDO instead, if possible. The MySQL extension is getting pretty old, and can't take advantage of any features past MySQL version 4.1.3. Look at http://www.php.net/manual/en/mysqli.overview.php for some details on the differences between the three interfaces.
Ben de bu sorun vardı. Benim kod incelerken ben bir bağlantıyı kapattı, bir script içerir bulmuştu, bu yüzden php kapatmak çalıştım yine hata var.
Bağlantı kapatmak için denemeden önce açıksa bu çözmek için, sadece kontrol:
yerine:
mysql_close($con);
Bunu yapın:
if( gettype($con) == "resource") {
mysql_close($con);
}