mysql - how to assign a mysqli query result value to a php variable? -
<?php $con=mysqli_connect("localhost","user","pass","db"); // check connection if (mysqli_connect_errno()){ echo "failed connect mysql: " . mysqli_connect_error(); } // perform queries $result = mysqli_query($con,"select count(*)\n" . "from information_schema.columns\n" . "where table_name = \'customerstable\'"); $something = mysqli_fetch_assoc($result); echo $something; mysqli_close($con); ?>
i want code echo value of something, number of columns in table. don't see printed. doing wrong?
your query wrong. below:-
<?php $con=mysqli_connect("localhost","user","pass","db"); if (mysqli_connect_errno()){ echo "failed connect mysql: " . mysqli_connect_error(); } $result = mysqli_query($con,"select count(*) total_count information_schema.columns table_name = 'customerstable'") or die(mysqli_error($con)); $something = mysqli_fetch_assoc($result); echo $something['total_count'];//or var_dump($something); mysqli_close($con); ?>
Comments
Post a Comment