Results 1 to 4 of 4

Thread: Does Anyone Know About Prepared Statements in MySQL? (Need help and explanation)

  1. #1
    Join Date
    Sep 2008

    Cool Does Anyone Know About Prepared Statements in MySQL? (Need help and explanation)

    Hello everyone. I'm trying to wrap my head around the concept of prepared statements and how to write them. Any assistance is much appreciated.

    Let's say that I want to inner join a table on a common column name and I want that first query to return column names only. then I want to run a query on that first query that looks for any blank values on those previous rows returned and I want that second query to return those rows that have a blank value.

    It's basically looking for blank values in matching rows returned without having to write those column names. Here's my attempt.

    PHP Code:
    SET @sql_select1 'SELECT * from information.schema.schemata
                 INNER JOIN orders ON `order`.CustomerID = `customers`.CustomerID'

    SET @sql_select1 CONCAT(@sql_select1'where schema_name = ""')

    PREPARE stmt from @sql_select1

    EXECUTE stmt

    I really need some help to understand how to do this. Thanks
    Last edited by ChuckB; 08-24-2013 at 04:54 PM.

  2. #2
    Join Date
    Jul 2013
    Here is a code that'll explain to you how its done using PDO.
    PHP Code:
    try { //create a connection to the database
    $conn = new PDO("mysql:localhost;dbname=test","username","password");
    } catch(
    PDOException $e) {
    $e->getMessage());//exit if failed to connect
    //the prepared statement
    $query $conn->prepare("SELECT * from customers INNER JOIN orders ON orders.CustomerID = customers.CustomerID where schema_name = :schema_name");
    //execute prepared statement
    $conn->execute(array('schema_name' => $schema_name));//value of the :schema_name
    $rows $conn->fetchAll(PDO::FETCH_ASSOC);//fetch all the results as an associative array

  3. #3
    Join Date
    Sep 2008
    I appreciate the response. I'm looking at it. However, I'm searching for how to use strictly the sql statement to run in phpmyadmin.

  4. #4
    Join Date
    Jul 2013
    Go to phpmyadmin, open your database, click on the sql panel(the panel that gives us a textbox to enter SQL queries and execute them).
    Type your query there and click on execute. Eg : SELECT * FROM employees ORDER BY lastname, firstname

    If you want to run prepared queries there, its not possible(as far as I know).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center