<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How would I insert and update my MySQL database using the this RestApi? in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-would-I-insert-and-update-my-MySQL-database-using-the-this/m-p/81192#M51181</link>
    <description>&lt;P&gt;There are multiple protocols that you can choose from, to set up the connection with your MySQL servers. These are as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;jdbc:mysql:&amp;nbsp;&lt;/STRONG&gt;This protocol helps set up ordinary &amp;amp; JDBC failover connections.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;jdbc:mysql:loadbalance:&amp;nbsp;&lt;/STRONG&gt;This protocol houses support for load balancing.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;jdbc:mysql:replication:&amp;nbsp;&lt;/STRONG&gt;This protocol helps set up JDBC-based replication connections.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You can further provide one or multiple hostnames in the “host parameter”, along with port numbers to specify host-specific properties. For example, you can create a connection URL as follows:&lt;/P&gt;&lt;P&gt;jdbc:mysql:replication//myUser:myPassword@[address=(host=myHost1)(port=1111)(key1=value1)]&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 06:02:40 GMT</pubDate>
    <dc:creator>EdwardCandisMaT</dc:creator>
    <dc:date>2022-02-09T06:02:40Z</dc:date>
    <item>
      <title>How would I insert and update my MySQL database using the this RestApi?</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-would-I-insert-and-update-my-MySQL-database-using-the-this/m-p/80869#M50958</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Being fairly new to Restful Api, I am in doubt as to how I would retrieve and update my MySQL database using the following PHP Restful API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;?php&lt;/P&gt;&lt;P&gt;// get the HTTP method, path and body of the request&lt;BR /&gt;$method = $_SERVER['REQUEST_METHOD'];&lt;BR /&gt;$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));&lt;BR /&gt;$input = json_decode(file_get_contents('php://input'),true);&lt;BR /&gt;&lt;BR /&gt;// connect to the mysql database&lt;BR /&gt;$link = mysqli_connect('localhost', 'user', 'pass', 'dbname');&lt;BR /&gt;mysqli_set_charset($link,'utf8');&lt;BR /&gt;&lt;BR /&gt;// retrieve the table and key from the path&lt;BR /&gt;$table = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));&lt;BR /&gt;$key = array_shift($request)+0;&lt;BR /&gt;&lt;BR /&gt;// escape the columns and values from the input object&lt;BR /&gt;$columns = preg_replace('/[^a-z0-9_]+/i','',array_keys($input));&lt;BR /&gt;$values = array_map(function ($value) use ($link) {&lt;BR /&gt;if ($value===null) return null;&lt;BR /&gt;return mysqli_real_escape_string($link,(string)$value);&lt;BR /&gt;},array_values($input));&lt;BR /&gt;&lt;BR /&gt;// build the SET part of the SQL command&lt;BR /&gt;$set = '';&lt;BR /&gt;for ($i=0;$i&amp;lt;count($columns);$i++) {&lt;BR /&gt;$set.=($i&amp;gt;0?',':'').'`'.$columns[$i].'`=';&lt;BR /&gt;$set.=($values[$i]===null?'NULL':'"'.$values[$i].'"');&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// create SQL based on HTTP method&lt;BR /&gt;switch ($method) {&lt;BR /&gt;case 'GET':&lt;BR /&gt;$sql = "select * from `$table`".($key?" WHERE id=$key":''); break;&lt;BR /&gt;case 'PUT':&lt;BR /&gt;$sql = "update `$table` set $set where id=$key"; break;&lt;BR /&gt;case 'POST':&lt;BR /&gt;$sql = "insert into `$table` set $set"; break;&lt;BR /&gt;case 'DELETE':&lt;BR /&gt;$sql = "delete `$table` where id=$key"; break;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// excecute SQL statement&lt;BR /&gt;$result = mysqli_query($link,$sql);&lt;BR /&gt;&lt;BR /&gt;// die if SQL statement failed&lt;BR /&gt;if (!$result) {&lt;BR /&gt;http_response_code(404);&lt;BR /&gt;die(mysqli_error());&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// print results, insert id or affected row count&lt;BR /&gt;if ($method == 'GET') {&lt;BR /&gt;if (!$key) echo '[';&lt;BR /&gt;for ($i=0;$i&amp;lt;mysqli_num_rows($result);$i++) {&lt;BR /&gt;echo ($i&amp;gt;0?',':'').json_encode(mysqli_fetch_object($result));&lt;BR /&gt;}&lt;BR /&gt;if (!$key) echo ']';&lt;BR /&gt;} elseif ($method == 'POST') {&lt;BR /&gt;echo mysqli_insert_id($link);&lt;BR /&gt;} else {&lt;BR /&gt;echo mysqli_affected_rows($link);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// close mysql connection&lt;BR /&gt;mysqli_close($link);&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 06:10:05 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-would-I-insert-and-update-my-MySQL-database-using-the-this/m-p/80869#M50958</guid>
      <dc:creator>DennisSebasiSte</dc:creator>
      <dc:date>2022-01-20T06:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: How would I insert and update my MySQL database using the this RestApi?</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-would-I-insert-and-update-my-MySQL-database-using-the-this/m-p/81192#M51181</link>
      <description>&lt;P&gt;There are multiple protocols that you can choose from, to set up the connection with your MySQL servers. These are as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;jdbc:mysql:&amp;nbsp;&lt;/STRONG&gt;This protocol helps set up ordinary &amp;amp; JDBC failover connections.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;jdbc:mysql:loadbalance:&amp;nbsp;&lt;/STRONG&gt;This protocol houses support for load balancing.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;jdbc:mysql:replication:&amp;nbsp;&lt;/STRONG&gt;This protocol helps set up JDBC-based replication connections.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You can further provide one or multiple hostnames in the “host parameter”, along with port numbers to specify host-specific properties. For example, you can create a connection URL as follows:&lt;/P&gt;&lt;P&gt;jdbc:mysql:replication//myUser:myPassword@[address=(host=myHost1)(port=1111)(key1=value1)]&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 06:02:40 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/How-would-I-insert-and-update-my-MySQL-database-using-the-this/m-p/81192#M51181</guid>
      <dc:creator>EdwardCandisMaT</dc:creator>
      <dc:date>2022-02-09T06:02:40Z</dc:date>
    </item>
  </channel>
</rss>

