PHP 使用 ADOdb 逻辑比较器
PHP with ADOdb logical comprators
大家好,当我使用 ADOdb 时,php 中的逻辑比较器有问题
因为当我在 table 中使用例如 CI 执行 select 时,结果永远不会为 NULL,而且我不能只验证该人在插入 [=12= 之前是否存在]
代码
<?php
include('inc/php/adodb5/adodb.inc.php');
$db = ADONewConnection('mysql'); # eg. 'mysql' or 'oci8', 'postgresql'
$db->debug = true;
// Establecer datos para comunicarse con el Gestor de Bases de Datos.
$server = "localhost";
$user = "x";
$password = "x";
$database = "xs";
// Traemos cositas del formulario de index.php
//$user=$_GET["username"];
$fecha = date('Y-m-d H:i:s');
$ci = $_GET["username"];
$db->Connect($server, $user, $password, $database) or die ("Se pudrio todo !");
$sql = "SELECT ciInterno_Persona_ciPersona FROM internos WHERE ciInterno_Persona_ciPersona = '".$ci."';";
$rs = $db->Execute($sql);
/////////////////////////
if($rs){
$sql = "INSERT INTO registrointernos VALUES ('', '0', '" .$fecha."', '".$ci."')";
$db->Execute($sql);
}else{
echo '<script language="javascript">alert("CI doesn't exist");</script>';
}
$rs->Close();
$db->Close();
?>
问题是 RS 的结果总是正确的,即使我在 table
中放置了一个不存在的 CI
提前感谢您的帮助
这是因为 $db->Execute($sql);
returns 派生 class of ADORecordSet
如果查询执行成功(文档 here)。
您必须执行以下操作:
$rs = $db->Execute($sql);
$rows = $rs->GetRows();
if (!empty($rows)) {
// ...
} else {
// ...
}
或者您可以使用 $db->GetRow($sql)
代替 $db->Execute($sql)
。
已解决,感谢解答
代码********
$sql = "sqlSentence";
$rs = $db->Execute($sql);
if($rs->fields(0)){
}
解决方法就是你要取什么sqlreturns,选择位置,做逻辑比较。
所以它保存在 $rs 中,但 $rs 就像一个数组,所以你必须把位置放在我的案例中 0 。及其完美的工作
大家好,当我使用 ADOdb 时,php 中的逻辑比较器有问题 因为当我在 table 中使用例如 CI 执行 select 时,结果永远不会为 NULL,而且我不能只验证该人在插入 [=12= 之前是否存在]
代码
<?php
include('inc/php/adodb5/adodb.inc.php');
$db = ADONewConnection('mysql'); # eg. 'mysql' or 'oci8', 'postgresql'
$db->debug = true;
// Establecer datos para comunicarse con el Gestor de Bases de Datos.
$server = "localhost";
$user = "x";
$password = "x";
$database = "xs";
// Traemos cositas del formulario de index.php
//$user=$_GET["username"];
$fecha = date('Y-m-d H:i:s');
$ci = $_GET["username"];
$db->Connect($server, $user, $password, $database) or die ("Se pudrio todo !");
$sql = "SELECT ciInterno_Persona_ciPersona FROM internos WHERE ciInterno_Persona_ciPersona = '".$ci."';";
$rs = $db->Execute($sql);
/////////////////////////
if($rs){
$sql = "INSERT INTO registrointernos VALUES ('', '0', '" .$fecha."', '".$ci."')";
$db->Execute($sql);
}else{
echo '<script language="javascript">alert("CI doesn't exist");</script>';
}
$rs->Close();
$db->Close();
?>
问题是 RS 的结果总是正确的,即使我在 table
中放置了一个不存在的 CI提前感谢您的帮助
这是因为 $db->Execute($sql);
returns 派生 class of ADORecordSet
如果查询执行成功(文档 here)。
您必须执行以下操作:
$rs = $db->Execute($sql);
$rows = $rs->GetRows();
if (!empty($rows)) {
// ...
} else {
// ...
}
或者您可以使用 $db->GetRow($sql)
代替 $db->Execute($sql)
。
已解决,感谢解答
代码********
$sql = "sqlSentence";
$rs = $db->Execute($sql);
if($rs->fields(0)){
}
解决方法就是你要取什么sqlreturns,选择位置,做逻辑比较。 所以它保存在 $rs 中,但 $rs 就像一个数组,所以你必须把位置放在我的案例中 0 。及其完美的工作