PHP ve MySQL uyarı soru Yardım?

2 Cevap php

Ben mysqli için mysql benim komut dönüştürmek için çalışıyorlar ve işlemi sırasında aşağıdaki hata aşağıda listelenen var.

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in on line 41

Warning: mysqli_error() expects exactly 1 parameter, 0 given in on line 43

Aşağıda tam kodudur.

<?php

require_once ('./mysqli_connect.php'); // Connect to the db.

if (isset($_POST['submitted'])) {

// Query member data from the database and ready it for display
	$mysqli = new mysqli("localhost", "root", "", "sitename");
	$dbc = mysqli_query($mysqli,"SELECT * FROM tags");
if (!$dbc) {
	// There was an error...do something about it here...
	print mysqli_error($mysqli);
}

// grab the tag
$tag = mysqli_real_escape_string($mysqli, $_POST['tag']);

// see if the tag already exists and potentially what the current count is
	$mysqli = new mysqli("localhost", "root", "", "sitename");
	$dbc = mysqli_query($mysqli,"SELECT id, count, page FROM tags WHERE tag='$tag'");

//--if there is a row, that means the tag exists
if(mysqli_num_rows($dbc))
{
//--pull out the tag ID and the current count and increment by one.
  $tag_info = mysqli_fetch_array($result);
  $tag_info_id = $tag_info["id"];
  $tag_info_count = $tag_info["count"] + 1;

//--update the table with the new count
  $sql_update_cnt = "UPDATE tags SET count='$tag_info_count' 
							WHERE id='$tag_info_id'";
  mysqli_query($sql_update_cnt);

  echo "$tag now with $tag_info_count instances";
}
else
{
// tag is not there, so insert a new instance
  $query = "INSERT INTO tags (tag, count) VALUES ('$tag', 1)";
if (!mysqli_query($query, $dbc))
  {
  die('Error: ' . mysqli_error());
  }
echo "1 record added";
}
mysqli_close($dbc);
}
?>

2 Cevap

yanlış diyorlar.

Olmalıdır $mysqli->query("SELECT * FROM tags");

$ Mysqli nesne ve sorgu bu nesne üzerinde yöntemdir. Sadece sorguda geçmek gerekir. Açıkçası mysqi_query tüm çağrılar maç için değiştirilmesi gerekir.

Ben geriye doğru bir adım atmak ve mysqli'nin için bir sarıcı kullanmak önerebilir miyim? Rob Poyntz son aylarda sürekli codesense_mysqli sarıcı kullanarak oldum ve ben bunun aksi MySQLi cruft sırf miktarını azaltmak için mükemmel olmak için bulduk sizin koduna döker.

Tabii ki başlık altında neler olup bittiğini bilmek iyidir, ama bazen bir, sadece çalışmak için araba alma temiz yöntem gereklidir.