All requests | > | Best PHP mysql to mysqli or PDO solution | > | Request new recommendation | > | Featured requests | > | No recommendations |
by mimso - Yesterday (2016-12-05)
+1 | I got php file in mysql and didn't know how to convert them <?php $host='127.0.0.1'; $uname='root'; $pwd=''; $db="cnb"; $con = mysql_connect($host,$uname,$pwd) or die("connection failed"); mysql_select_db($db,$con) or die("db selection failed"); $secnbid = $_REQUEST['se_cnbid']; $seuid = $_REQUEST['se_uid']; if($secnbid == 1) {
} if($secnbid == 2) {
} if($secnbid == 3) {
} if($secnbid == 4) {
} print(json_encode($flag)); mysql_close($con); ?> |
1. by Dave Smith - 3 hours ago (2016-12-06) Reply
<?php $host='127.0.0.1'; $uname='root'; $pwd=''; $db="cnb";
$con = mysqli_connect($host,$uname,$pwd,$db) or die("connection failed");
$secnbid = $_REQUEST['se_cnbid']; $seuid = $_REQUEST['se_uid'];
$proc = true; switch($secnbid){ case 1: $query = "select * from admin where ad_id = '$seuid'"; $col = 'ad_name'; $flag['se_cnb'] = 'Admin'; break; case 2: $query = "select * from hod where ho_id = '$seuid'"; $col = 'ho_name'; $flag['se_cnb'] = 'HOD'; break; case 3: $query = "select * from staff where stf_id = '$seuid'"; $col = 'stf_name'; $flag['se_cnb'] = 'Staff'; break; case 4: $query = "select * from student where std_id = '$seuid'"; $col = 'std_name'; $flag['se_cnb'] = 'Student'; break; default: $proc = false; }
if($proc){
$r = mysqli_query($con,$query); $row = mysqli_fetch_assoc($r); $flag['se_name'] = $row[$col];
print(json_encode($flag));
}else{ //request out of range } ?>
2. by Dave Smith - 3 hours ago (2016-12-06) in reply to comment 1 by Dave Smith Comment
<?php
$host='127.0.0.1';
$uname='root';
$pwd='';
$db="cnb";
$con = mysqli_connect($host,$uname,$pwd,$db) or die("connection failed");
$secnbid = $_REQUEST['se_cnbid'];
$seuid = $_REQUEST['se_uid'];
$proc = true;
switch($secnbid){
case 1:
$query = "select * from admin where ad_id = '$seuid'";
$col = 'ad_name';
$flag['se_cnb'] = 'Admin';
break;
case 2:
$query = "select * from hod where ho_id = '$seuid'";
$col = 'ho_name';
$flag['se_cnb'] = 'HOD';
break;
case 3:
$query = "select * from staff where stf_id = '$seuid'";
$col = 'stf_name';
$flag['se_cnb'] = 'Staff';
break;
case 4:
$query = "select * from student where std_id = '$seuid'";
$col = 'std_name';
$flag['se_cnb'] = 'Student';
break;
default:
$proc = false;
}
if($proc){
$r = mysqli_query($con,$query);
$row = mysqli_fetch_assoc($r);
$flag['se_name'] = $row[$col];
print(json_encode($flag));
}else{
//request out of range
}
?>
+1 | by Manuel Lemos 16150 - 4 hours ago (2016-12-06) Comment The fastest way to migrate your code to work with mysqli is to use this package that provides mysql replacement functions that internally use mysqli functions. |
Recommend package | |
|