• Resolved Ashfaq Ahmed Nizamani

    (@ashfaq-ahmed-nizamani)


    Hello all
    I am new in learning every web development tools one needs. For the past little over two months I am learning on my own using the Internet as a great library.

    Question: Is is O.K if I integrate my own PHP code and handle every possible attacks and develop some kind of application that requires dbms. I can handle that on my own. Since I don’t know how to really mix the two i.e WordPress and my own developed PHP code. All I know right now is that it is much easier for me to call my PHP code and from there on I will be using my code. Although I can go back to the WordPress page or the default wordpress blog index page.

    Kindly help if there is a way to properly integrate the two.

    P.S. I am using the local machine right now for practicing.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    You mean like with a Plugin?

    Thread Starter Ashfaq Ahmed Nizamani

    (@ashfaq-ahmed-nizamani)

    Well something like that. What I really mean is that when I integrate by calling one of the php from one of the page inside wordpress it works. But if I can not call those php files from within wordpress php files.

    May be like plugin, because plugins work just fine. Although I know a little bit of creating my own plugin do you recommend to use my php code by using those inside a plugin?

    Thread Starter Ashfaq Ahmed Nizamani

    (@ashfaq-ahmed-nizamani)

    Hi,
    It seems every one is so busy these days that no one has time to give a helping hand!

    I am trying to work with MySQL from within a Page of WordPress but so far not successful. Although I can create a link inside the page and call a php file and then that php file takes over and every thing works fine. This means I can even work with MySQL as well. I have done this.

    But what I really want is how to use the same working php code inside the wordpress page. I have tried couple of plugins. Such as (insert PHP) for insert the php code within the wordpress page but this again does not allow to work with MySQL. Tried even inserting the code inside a template page but even then it does not work.

    Tried and created a simple plugin and used the same code inside that plugin of my own but the issue remains the same. The database connection does not materialize.

    Please HELP!!!

    Here is the code I am using:

    <?php
    DEFINE (‘DB_USER’, ‘root22’);
    DEFINE (‘DB_PASSWORD’, ”);
    DEFINE (‘DB_HOST’, ‘localhost’);
    DEFINE (‘DB_NAME’, ‘sitename’);

    $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die (‘Could not connect to MySQL: ‘ . mysqli_connect_error() );
    mysqli_set_charset($dbc, ‘utf8’);
    echo ‘<h1>Registered Users</h1>’;
    $q = “SELECT CONCAT(last_name, ‘, ‘, first_name) AS name, DATE_FORMAT(registration_date, ‘%M %d, %Y’) AS dr FROM users ORDER BY registration_date ASC”;

    $r = @mysqli_query ($dbc, $q); // Run the query.
    $num = mysqli_num_rows($r);

    if ($num > 0) {
    echo “<p>There are currently $num registered users.</p>\n”;

    echo ‘<table align=”center” cellspacing=”3″ cellpadding=”3″ width=”75%”>
    <tr><td align=”left”><b>Name</b></td><td align=”left”><b>Date Registered</b></td></tr>’;

    while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
    echo ‘<tr><td align=”left”>’ . $row[‘name’] . ‘</td><td align=”left”>’ . $row[‘dr’] . ‘</td></tr>’;
    }

    echo ‘</table>’;

    mysqli_free_result ($r);

    } else {
    echo ‘<p>There are currently no registered users.</p>’;
    }
    mysqli_close($dbc);
    ?>

    If you’re using it inside a pages content, then set up a shortcode that calls that code.

    If you’re using it somewhere else in the template you can either set it up directly in the PHP template file, or you can create a new function in your themes functions.php file that uses that code.

    You can also create a new pluign for it if you really want to. That way you could incorporate both of the things that I’ve said above, so it’s a more inclusive way of doing things.

    Thread Starter Ashfaq Ahmed Nizamani

    (@ashfaq-ahmed-nizamani)

    Thank you very much All.
    I have done it. I know how to list all records, delete specific record, insert a record, search a record and sort records.

    Yes all in a page or in a custom template page.

    Now I understand how to work with MySQL databases from independent php files or from wordpress pages. The two approaches are bit different. The first one gives you quite independence while the other has some restrictions. The methods of $wpdb are sufficient to design any kind of database you like as long as you work inside the same database which WordPress uses.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Mixing WordPress plus my own PHP code’ is closed to new replies.