close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

converting to mysqli

Thread began 6/24/2014 3:09 am by Jamie | Last modified 7/01/2014 8:47 am by Jason Byrnes | 4137 views | 21 replies |

Jamie

converting to mysqli

Hi Jason

How would I convert this code to a mysqli version please?

<?php
$chk_rows = mysql_num_rows($SpecialOffersPanel);
if ($chk_rows > 0) {
mysql_data_seek($SpecialOffersPanel, 0);
$row_SpecialOffersPanel = mysql_fetch_assoc($SpecialOffersPanel);
}
?>
<?php if ("".$showError ."" != "0") { ?>

<?php } ?>



and this one that i use with mod re-wrting

<?php
$colname_PageContentsPerm = "-1";
if (isset($_GET['perm'])) {
$colname_PageContentsPerm = $_GET['perm'];
}

$colname_PageContents = "-1";
if (isset($_GET['id'])) {
$colname_PageContents = $_GET['id'];
}
mysql_select_db($database_PowerCMSConnection, $PowerCMSConnection);
$query_PageContents = sprintf("SELECT * FROM services_plumbing WHERE ProductContentsID = %s OR Permalink = %s AND Live = 1", GetSQLValueString($colname_PageContents, "text"),GetSQLValueString($colname_PageContentsPerm, "text"));
$PageContents = mysql_query($query_PageContents, $PowerCMSConnection) or die(mysql_error());
$row_PageContents = mysql_fetch_assoc($PageContents);
$totalRows_PageContents = mysql_num_rows($PageContents);
?>



All its doing is checking to see if the contents of the table have been set to live (1) or not (0) and if 0 then nothing shows in the front end

Thanks

Jamie

Sign in to reply to this post

Jason ByrnesWebAssist

The first code block is to reset the recordset to the first record. in mysqly, use the following:

<?php 
if($RecordsetName->atEnd()) {
$RecordsetName->moveFirst();
}
?>




The second code block is a standard recordset with parameters.

Examine the original recordset by editing it in DW to open the DW recordset panel.

Note the SQL and the parameters that are displayed, the names, type, default value and run time value for each.

then open the MySQLi recordset panel to recreate it.

Sign in to reply to this post

Jamie

thanks for the reply Jason

Re the 2nd code block, I am able to get to a certain point:

<?php
$PageContents = new WA_MySQLi_RS("PageContents",$DBConnection,1);
$PageContents->setQuery("SELECT * FROM special_offers WHERE OffersID = ? OR Permalink = ? AND Live = 1");
$PageContents->bindParam("s", "".$_GET['id'] ."", "-1"); //colname
$colname_PageContentsPerm->bindParam("s", "".$_GET['perm'] ."", "-1"); //colname
$PageContents->execute();
?>



but its the line from the original that I cannot see how to incorporate as mysqli:

GetSQLValueString($colname_PageContents, "text"),GetSQLValueString($colname_PageContentsPerm, "text"));
Sign in to reply to this post

Jason ByrnesWebAssist

that code:
GetSQLValueString($colname_PageContents, "text"),GetSQLValueString($colname_PageContentsPerm, "text"));

is how the variables are added to the SQL.

in MySQLi, the variables are added to the SQL using these 2 lines:
$PageContents->bindParam("s", "".$_GET['id'] ."", "-1"); //colname
$colname_PageContentsPerm->bindParam("s", "".$_GET['perm'] ."", "-1"); //colname

Sign in to reply to this post

Jamie

i cant seem to get it to work

I get the following on page error:

Notice: Undefined index: OffersID in C:\xampp\htdocs\street\promotion-s.php on line 6

Notice: Undefined variable: colname_PageContentsPerm in C:\xampp\htdocs\street\promotion-s.php on line 7

Fatal error: Call to a member function bindParam() on a non-object in C:\xampp\htdocs\street\promotion-s.php on line 7



Have attached the htaccess file and the target page

Sign in to reply to this post

Jason ByrnesWebAssist

1) It looks like you used the same name for both variables in the recordset. When I open it in the recordset panel, the SQL shows as:

SELECT *
FROM special_offers
WHERE OffersID = colname OR Permalink = colname AND Live = 1

change that so it uses unique names

SELECT *
FROM special_offers
WHERE OffersID = paramOffersID OR Permalink = paramPermalink AND Live = 1


then create the variables as:
name: paramOffersID
Type: integer
default value: -1
Run Time Value: <?php echo(isset($_GET['id'])?$_GET['id']:""); ?>

name: paramPermalink
Type: text
default value: -1
Run Time Value: <?php echo(isset($_GET['perm'])?$_GET['perm']:""); ?>

Sign in to reply to this post

Jamie

thanks Jason. Now its 404ing :(

Sign in to reply to this post

Jason ByrnesWebAssist

404 is page not found. That sounds like a problem in the htaccess. what if you remove the htaccess file and access the page directly rather than using the rewrite rule.

Sign in to reply to this post

Jamie

yeah I can access it fine if I dont use the rewrite but am just trying to convert the code that I have re-used multiple times but now to mysqli .....

Sign in to reply to this post

Jason ByrnesWebAssist

MySQLi has nothing to do with the rewrite

something in the htaccess is causing the rewrite rule to malfunction.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...