在这里,我想将$part1
和$part2
值分配给Mysqli查询。但是问题是$part2
值没有进入查询。我无法找到我的代码会出现什么问题。
$string = 'Enter a domain name' . "\r\n";
socket_write($client, $string, strlen($string)) or die("Could not write output\n");
$str = '';
while ($input = socket_read($client, 1024)) {
$str .= $input;
if (strpos($str, "\n") !== false) {
break 1;
}}
$part = explode(".", $str);
$part1 = $part[0];
$part2= $part[1];
$sql = "SELECT DomainCategory.Name "
. "FROM DomainName_Client, DomainNameType, DomainCategory, OrderDomain_Client "
. "WHERE DomainName_Client.Name='$part1' "
. "AND DomainNameType.Name='$part2' "
. "AND DomainName_Client.TypeID=DomainNameType.ID "
. "AND DomainCategory.ID=DomainName_Client.DomainCategoryID "
. "AND OrderDomain_Client.DomainNameID=DomainName_Client.ID";
$result = $mysqli->query($sql);
$row1 = $result->num_rows;
if ($row1 > 0) {
$row = $result->fetch_array(MYSQLI_NUM);
printf("%s\n", $row[0]);
} else {
echo 'This is not a Registered Domain';
}
答案 0 :(得分:2)
与PDO联系
try { $dbh = new PDO("pgsql:host=$host;port=5432;dbname=$db;user=$user;password=$pass"); echo "Connected"; } catch (Exception $e) { echo "Unable to connect: " . $e->getMessage() ."
"; }
准备你的声明:
$sth = $dbh->prepare("SELECT DomainCategory.Name " . "FROM DomainName_Client, DomainNameType, DomainCategory, OrderDomain_Client " . "WHERE DomainName_Client.Name='?' " . "AND DomainNameType.Name='?' " . "AND DomainName_Client.TypeID=DomainNameType.ID " . "AND DomainCategory.ID=DomainName_Client.DomainCategoryID " . "AND OrderDomain_Client.DomainNameID=DomainName_Client.ID");
执行:
`enter code here` $sth->execute(array($part1, $part2)); $red = $sth->fetchAll();
答案 1 :(得分:2)
根据Combinu的建议,PDO是更好的方法。但是,为了配合你的想法,我会连接变量的内容。
$scope.retrieveClientName = function(store) { // pass in store so we can attach results here
$http({
method: 'GET',
url: 'http://mywebsite.com/api/v1/clients?client_id='+store.client_id
}).
success(function(data, status, headers, config) {
return store.clients = data; // attach result in object
}).
error(function(data, status, headers, config) {
$scope.name = 'Error!';
});
}
$http({
method: 'GET',
url: 'http://mywebsite.com/api/v1/stores/'
}).
success(function(data, status, headers, config) {
$scope.stores = data;
angular.forEach($scope.stores, function(store){
$scope.retrieveClientName(store); // no need .then here
});
}).
error(function(data, status, headers, config) {
$scope.name = 'Error!';
});
<tbody>
<tr ng-repeat="store in stores">
<td>{{store.name}}</td>
<td> {{store.type}} </td>
<td><span ng-repeat="client in store.clients"> <!-- use data here -->
{{client.name}}
</span>
</td>
<td>{{store.address}}</td>
</tr>
</tbody
答案 2 :(得分:1)
使用{$ part2}并检查$ part2在asignment之后是否有值
$sql = "SELECT DomainCategory.Name "
. "FROM DomainName_Client, DomainNameType, DomainCategory, OrderDomain_Client "
. "WHERE DomainName_Client.Name='{$part1}' "
. "AND DomainNameType.Name='{$part2}' "
. "AND DomainName_Client.TypeID=DomainNameType.ID "
. "AND DomainCategory.ID=DomainName_Client.DomainCategoryID "
. "AND OrderDomain_Client.DomainNameID=DomainName_Client.ID";
答案 3 :(得分:1)
使用Join Query而不是简单选择Query with where condition
`"SELECT DomainCategory.Name FROM DomainName_Client join DomainNameType on DomainNameType.ID = DomainName_Client.TypeID join DomainCategory on DomainCategory.ID=DomainName_Client.DomainCategoryID join OrderDomain_Client on OrderDomain_Client.DomainNameID=DomainName_Client.ID WHERE DomainName_Client.Name = '".$part1."' AND DomainNameType.Name = '".$part2."'";`