这是我的脚本,它验证了username
已经采取的措施.
while ($row = mysql_fetch_array($result))
{
$usname=$row['Username'];
}
if ($usname!=$uname)
{
} else {
echo "Username taken!";
die;
}
Run Code Online (Sandbox Code Playgroud)
它运作良好.如果采用a username
,它不会将其添加到数据库中,如果它是无人认领的.但我总是得到这个恼人的错误:
注意:未定义的变量:第29行的C:\ xampp\htdocs\insert.php中的usname
我定义了那个变量!
救命...
class a {
public function getContinents () {
// connect to db
$res = $this->db->query("SELECT continent FROM mytable");
return $res;
}
}
$obj = new a();
$getContinents = $obj->getContinents();
Run Code Online (Sandbox Code Playgroud)
因此,如果我们在这里检查变量getContinents,它是一个有效的mysqli-result对象
var_dump($getContinents);
Run Code Online (Sandbox Code Playgroud)
结果是
object(mysqli_result)#4 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> NULL ["num_rows"]=> int(6) ["type"]=> int(0) }
Run Code Online (Sandbox Code Playgroud)
现在我想序列化和反序列化这个对象
$getContinents_to_str = serialize($getContinents);
var_dump(unserialize($getContinents_to_str));
Run Code Online (Sandbox Code Playgroud)
结果是
Warning: var_dump(): Property access is not allowed yet in ...
object(mysqli_result)#5 (5) { ["current_field"]=> NULL ["field_count"]=> NULL ["lengths"]=> NULL ["num_rows"]=> NULL ["type"]=> NULL }
Run Code Online (Sandbox Code Playgroud)
请告诉我为什么会这样?哪里错了?
我有以下 PHP 代码,它基本上获取 MySQL 查询的结果:
$q2 = "SELECT FIELD FROM TABLENAME WHERE ID = 1;";
$con = new mysqli($server, $user, $pass);
if (mysqli_connect_errno())
{
$error = mysqli_connect_error();
exit();
}
else
{
$res = mysqli_query($con, $q2);
if ($res)
{
while($row = mysqli_fetch_assoc($res))
{
PRINT "THERE WAS A RESULT HERE: ";
}
}
else
{
$error = mysqli_error();
exit();
}
mysqli_free_result($res);
};
mysqli_close($con);
Run Code Online (Sandbox Code Playgroud)
但有时,它会返回一个空值。根据父应用程序的工作方式,这是有效的,但我如何检测该空行并返回“这是一个空行:”?
我有简单的模型,需要将数据插入到我的表中.当我使用sql和查询时,一切正常,但当我尝试使用插入函数时,我得到一个错误,我需要使用设置?
我的数据库中的id是自动增量,日期是时间戳
class Article extends CI_Model {
private $id;
private $title;
private $text;
private $date;
public function __construct()
{
$this->load->database();
}
public function save_article($title,$text)
{
$this->title=$title;
$this->text=$text;
$this->id='';
$this->load->helper('date');
$this->date=now();
print_r($this);
//"INSERT INTO article VALUES ('','".$title."','".$text."',NOW())")
$this->db->insert('articles',$this);
}
}
Run Code Online (Sandbox Code Playgroud)
Article Object([id:Article:private] => [title:Article:private] => rrrrrrrrrrr [text:Article:private] => rrrrrrrrrrrrrrrrrr [date:Article:private] => 1351680951)
发生数据库错误
您必须使用"set"方法更新条目.
文件名:C:\ Program Files(x86)\ EasyPHP-12.1\www\blog\system\database\DB_active_rec.php
行号:1174
我尝试在xampp
运行时安装xdebug php 5.4.4
,花了几个小时后,我仍然无法安装它!
这是我在php.ini中的设置
zend_extension = "Z:\xampp\php\ext\php_xdebug-2.2.1-5.4-vc9-x86_64.dll"
xdebug.remote_mode = "req"
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.profiler_enable=1
xdebug.profiler_output_dir="Z:\xampp\tmp"
Run Code Online (Sandbox Code Playgroud)
谁能发现任何错误?
谢谢