SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not able to connect to MYsql with php

    Hi,

    I am using XAMPP & I am not able to connect MySQL with PHP. I am a novice & learning from a book "php_mysql novice to ninja 5th edition"

    when I type the following query in PhpMyAdmin


    <?php
    try
    {
    $pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser',
    'mypassword');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->exec('SET NAMES "utf8"');
    }
    catch (PDOException $e)
    {
    $output = 'Unable to connect to the database server.';
    exit();
    }


    I get the following error.


    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php
    try
    {
    $pdo = new PDO('mysql:host=localhost:8888;dbname=ijdb', 'ijdbuser',
    '' at line 1


    Please help me to solve this problem

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,402
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    It looks like you're putting PHP code into phpMyAdmin when it's expecting SQL. If you want to test the code you've shown above, you need to put it in a file with a .php extension and then run it from your server.


Bookmarks

Posting Permissions

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