Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Could someone translate my MySQL PHP file to a MySQLI PHP file?

I have a simple select MySQL query which i need to transfer to MySQLI. I would also need to have prepared statements.

If anyone could help me please reply or PM me.

Thanks, James.
Ctrl-R "mysql_" with "mysqli_".

How to use prepared statements: http://php.net/manual/en/mysqli.quicksta...ements.php
You wouldn't learn a thing if someone changed it for you. Change it yourself.
I would Love to but i don't use mysql or mysqli ,i only use PDO in my websites.
(Jul 20, 2014 11:35 AM)Lumia Wrote:  I would Love to but i don't use mysql or mysqli ,i only use PDO in my websites.

If you can't help, then why bother posting?

(Jul 20, 2014 10:23 AM)jamesgates1 Wrote:  I have a simple select MySQL query which i need to transfer to MySQLI. I would also need to have prepared statements.

If anyone could help me please reply or PM me.

Thanks, James.

Try it yourself, and if you get stuck then post back here. You'll learn a lot more by trying to do it yourself than just getting someone else to do it for you.
PHP internals developer
Trial, and error is the best remedy for these sort's of problem's. Did our parent's teach us to use computer's the way we use them now? No. We taught ourselves via the vast information span that was already available upon release of what we now call the "Internet".

If you are still stuck after trying to do it yourself please feel free to drop me a PM, and I'd be glad to help you out.

Good luck, and Best wishes.
~Vource :Blackhat:
BTC - 16LkP8M9fspzm8kPfRPvvpMaCf1SMENMxA
Help me earn a couple extra cents! http://vource.bestgalleries.me Click the Ads. Thank's! <3
I appreciate the replies and understand i need to learn for myself but i have already tried 3 times on stack overflow with people showing me different methods. What i want to do is to receive a JSON output of all output records but currently all i receive is: "string(3) "the" string(81) "SELECT `ID`, `NewsStory`, `Summary1`, `Summary2` FROM `Articles` WHERE `Tags` = ?"". If you could give me an explanation with the edits then that would help me to understand.

PHP Code

    <?php
    
//Open a new connection to the MySQL server
    
$mysqli = new mysqli('localhost','createyo_james','password','createyo_TestDatabase');

    
//Output any connection error
    
if ($mysqli->connect_error) {
        die(
'Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
    }
    
$myArray = array();
    
$Tags = $_GET["Tags"];

    
var_dump($_GET["Tags"]);

    
$query = "SELECT `ID`, `NewsStory`, `Summary1`, `Summary2` FROM `Articles` WHERE `Tags` = ?";

    
$statement = $mysqli->prepare($query);
    
var_dump($query);
    
//bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
    
$statement->bind_param('s', $Tags);

    if(
$statement->execute()){
    
$tempArray = array();
          while(
$row = $result->fetch_object()) {
                
$tempArray = $row;
                
array_push($myArray, $tempArray);
          }
          echo 
json_encode($myArray);

        
$result->close();
        
$mysqli->close();
        }else{
        die(
'Error : ('. $mysqli->errno .') '. $mysqli->error);
    }
    
$statement->close();

    
?>

Thanks, James.
(Jul 20, 2014 03:04 PM)jamesgates1 Wrote:  I appreciate the replies and understand i need to learn for myself but i have already tried 3 times on stack overflow with people showing me different methods. What i want to do is to receive a JSON output of all output records but currently all i receive is: "string(3) "the" string(81) "SELECT `ID`, `NewsStory`, `Summary1`, `Summary2` FROM `Articles` WHERE `Tags` = ?"". If you could give me an explanation with the edits then that would help me to understand.

PHP Code

    <?php
    
//Open a new connection to the MySQL server
    
$mysqli = new mysqli('localhost','createyo_james','password','createyo_TestDatabase');

    
//Output any connection error
    
if ($mysqli->connect_error) {
        die(
'Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
    }
    
$myArray = array();
    
$Tags = $_GET["Tags"];

    
var_dump($_GET["Tags"]);

    
$query = "SELECT `ID`, `NewsStory`, `Summary1`, `Summary2` FROM `Articles` WHERE `Tags` = ?";

    
$statement = $mysqli->prepare($query);
    
var_dump($query);
    
//bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
    
$statement->bind_param('s', $Tags);

    if(
$statement->execute()){
    
$tempArray = array();
          while(
$row = $result->fetch_object()) {
          
$tempArray = $row;
          
array_push($myArray, $tempArray);
          }
          echo 
json_encode($myArray);

        
$result->close();
        
$mysqli->close();
        }else{
        die(
'Error : ('. $mysqli->errno .') '. $mysqli->error);
    }
    
$statement->close();

    
?>

Thanks, James.
You just said that its people showing you methods on stack overflow, that doesn't sound like trying to learn for your self... This code you posted is the oop method used in mysqli. I would go with procedural if your moving from mysql_* functions.
(Jul 20, 2014 03:55 PM)MineSQL Wrote:  You just said that its people showing you methods on stack overflow, that doesn't sound like trying to learn for your self... This code you posted is the oop method used in mysqli. I would go with procedural if your moving from mysql_* functions.
Oop is seen as the best of the two

Thanks, James.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by ClumsySep 11, 2026 11:14 PM 0 52 Sep 11, 2026 11:14 PM
Last Post: Clumsy
by BrazzinoApr 20, 2023 09:49 AM 4 157 Apr 20, 2023 09:49 AM
Last Post: Brazzino
[PHP] by CodepacksJun 26, 2019 08:20 PM 3 176 Jun 26, 2019 08:20 PM
Last Post: Oxycodone